package com.software.aperture.controller;

import com.software.aperture.bean.Post;
import com.software.aperture.service.PostService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("post")
public class PostController {

    @Resource
    private PostService postService;

    @RequestMapping("/getAllPosts")
    public List<Post> getPost(){
        return postService.getAllPosts();
    }

    @RequestMapping("/getPostById/{postId}")
    public Optional<Post> getPostById(@PathVariable("postId") Integer postId){
        return postService.getPostById(postId);
    }

    @RequestMapping(value = "/addPost",method = RequestMethod.POST)
    public void addPost(@RequestBody Post post){
        postService.addPost(post);
    }

    @RequestMapping(value = "/deletePost/{postId}",method = RequestMethod.POST)
    public void deletePost(@PathVariable("postId") Integer postId){
        postService.deletePostById(postId);
    }

    @RequestMapping(value = "/updatePost",method = RequestMethod.POST)
    public void updatePost(@RequestBody Post post){
        postService.updatePost(post);
    }

}
